﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using GBT.SystemEnties;
using Microsoft.AspNetCore.Mvc;
using NLog;
using PersistenceDataLogic.Core;
using QueryDataLogic.Core;

namespace WebAPI_QiSiMealSystem.Controllers
{
    [Route("gbt/[controller]")]
    [ApiController]
    public class TakeFoodRecordController : ControllerBase
    {
        private static Logger logger = LogManager.GetCurrentClassLogger();
        TakeFoodRecordManage takeFoodRecordManage = new TakeFoodRecordManage();
        OperationTakeFoodRecord operationTakeFoodRecord = new OperationTakeFoodRecord();

        // GET: gbt/TakeFoodRecord
        [HttpGet]
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }

        // POST: gbt/TakeFoodRecord/GetTakeFoodRecord
        [HttpPost("GetTakeFoodRecord")]
        public async Task<IActionResult> GetTakeFoodRecord([FromBody] System_TakeFoodRecord value)
        {
            OkObjectResult task = await Task.Run(() =>
            {
                int totalNumber = 0;
                int totalPage = 0;
                string Error = "";
                object result = null;
                try
                {
                    result = takeFoodRecordManage.GetTakeFoodRecord(value, ref totalNumber, ref totalPage);
                }
                catch (Exception ex)
                {
                    Error = ex.Message + Environment.NewLine + ex.StackTrace;
                    logger.Error(ex);
                }
                return Ok(new { root = result, Error, totalNumber, totalPage });
            });
            return task;
        }

        // POST: gbt/TakeFoodRecord/AddOrModifyTakeFoodRecord
        [HttpPost("AddOrModifyTakeFoodRecord")]
        public async Task<IActionResult> AddOrModifyTakeFoodRecord([FromBody] TakeFoodRecord value)
        {
            OkObjectResult task = await Task.Run(() =>
            {
                string Error = "";
                string msg = "";
                TakeFoodRecord result = null;
                try
                {
                    result = operationTakeFoodRecord.AddOrModifyTakeFoodRecord(value, ref msg);
                }
                catch (Exception ex)
                {
                    Error = ex.Message + Environment.NewLine + ex.StackTrace;
                    logger.Error(ex);
                }
                return Ok(new { root = result, msg, Error });
            });
            return task;
        }

        // POST: gbt/TakeFoodRecord/DeleteTakeFoodRecord
        [HttpPost("DeleteTakeFoodRecord")]
        public async Task<IActionResult> DeleteTakeFoodRecord([FromBody] System_TakeFoodRecord value)
        {
            OkObjectResult task = await Task.Run(() =>
            {
                bool data = false;
                string Error = "";
                try
                {
                    data = operationTakeFoodRecord.DeleteTakeFoodRecord(value);
                }
                catch (Exception ex)
                {
                    Error = ex.Message + Environment.NewLine + ex.StackTrace;
                    logger.Error(ex);
                }
                return Ok(new { root = data, Error });
            });
            return task;
        }

        // POST: gbt/TakeFoodRecord
        [HttpPost]
        public void Post([FromBody] string value)
        {
        }

        // PUT: gbt/TakeFoodRecord/5
        [HttpPut("{id}")]
        public void Put(int id, [FromBody] string value)
        {
        }

        // DELETE: gbt/ApiWithActions/5
        [HttpDelete("{id}")]
        public void Delete(int id)
        {
        }
    }
}
